// 点击停留
class Menu{
    constructor(ops){
        this.options = ops.options;
        this.addEvent();
    }
    addEvent(){
        for(let i=0;i<this.options.length;i++){
            this.options[i].addEventListener("click",()=>{
                for(let j=0;j<this.options.length;j++){
                    this.options[j].className = "";
                }
                // this.index = i;
                this.options[i].className = "active";
            })
            
        }
    }
}
new Menu({
    options:document.querySelectorAll(".subnav_list a")
})
// 渲染底部商品
class Foot{
    constructor(ops){
        this.cont = ops.cont;
        this.url = "http://localhost:2926/api?type=personal"
        this.load();
    }
    load(){
        ajaxGet(this.url,res=>{
            this.res = JSON.parse(res);
            this.render();
        })
    }
    render(){
        let str = "";
        this.res.data.forEach(val=>{
            str +=`<div class="product_itme" index="${val.proId}">
                        <a href="./productList.html">
                            <div class="product_itme_img">
                                <img src="${val.url}" alt="">
                            </div>
                            <h2 class="product_itme_title">${val.name}</h2>
                            <p class="product_itme_price">￥${val.price}</p>
                        </a>
                    </div>`
        })
        this.cont.innerHTML = str;
    }
}
new Foot({
    cont:document.querySelector(".product_list")
})
// 登录改变
class Whethertologin{
    constructor(){
        this.userMsg = document.querySelector(".userMsg");
        this.last_a = document.querySelector(".last_a a");
        this.addEvent();
        this.isLogin();
    }
    isLogin(){
        if(localStorage.getItem("isLogin") === "YES"){
            this.userMsg.innerHTML = `&nbsp;${localStorage.getItem("username")} 新华伴您畅游书海。`;
        }else{
            location.href = "./login.html";
        }
    }
    addEvent(){
        this.last_a.addEventListener("click",()=>{
            localStorage.setItem("isLogin","");
        })
    }
}
new Whethertologin();